import { createRouter, createWebHashHistory } from 'vue-router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

const routes = [
  {
    path: '/',
    name: 'code',
    redirect: '/edit',
    component: () => import('../views/layout/LayoutView'),
    children: [
      {
        path: '/edit',
        name: 'edit-view',
        meta: {
          keepAlive: true // 需要缓存
        },
        component: () => import('../views/edit-view/EditView')
        // components: {
        //   keepAlive: () => import('../views/edit-view/EditView')
        // }
      },
      {
        path: '/code',
        name: 'code-view',
        meta: {
          keepAlive: false
        },
        component: () => import('../views/code-view/CodeView')
      }
    ]
  },
  {
    path: '/:pathMatch(.*)',
    component: () => import('../views/err-views/NotFoundView')
  }
  // {
  //   path: '/about',
  //   name: 'about',
  //   component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  // }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

const np = NProgress
np.inc()
// np.configure({ easing: 'ease', speed: 500, showSpinner: false })
router.beforeEach(async (to, from, next) => {
  np.start()
  next()
})
router.afterEach(() => {
  np.done()
})

export default router
